package PublishSubscribe;

import Utils.ConnectionFactoryUtil;
import com.rabbitmq.client.*;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @ClassName ConsumerMailTow
 * @Description TDD
 * @Author 混沌酱
 * @Date 2023-10-10 15:21
 * @Version 1.0
 **/
public class ConsumerMailTow {

    public static void main(String[] args) throws IOException, TimeoutException {
        Connection connection = ConnectionFactoryUtil.getConnection();
        Channel channel = connection.createChannel();
        channel.basicConsume("SEND_MAIL", true, new DefaultConsumer(channel) {
            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                super.handleDelivery(consumerTag, envelope, properties, body);
                String message = new String(body, "UTF-8");
                System.out.println(message);
            }
        });
    }
}
